#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QThread>
#include <QSerialPort>
#include <QSerialPortInfo>

#include "candevice.h"
#include "canopen_sdo.h"
#include "http_thread.h"
#include "websocket_thread.h"


QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    uint32_t stringToUint(QString str);
    QString uintToString(uint32_t data);
    void search_serial_port(void);
    static QByteArray hexStringToByteArray(const QString &hexString);

private slots:
    void on_connet_button_clicked();

    void update_text_lable(Param *param);
    void updata_hou_status(Param * param);
    void updata_bdu_status(Param * param);
    void updata_wdu_status(Param * param);
    void updata_pmu_status(Param * param);

    void updata_bud_param_lable(OdParam *odparam);
    void updata_mcu_version(OdParam *odparam);
    void updata_bdu_param(OdParam *odparam);

    void on_read_param_clicked();
    void on_get_mcu_version_clicked();

    void brush_power_gear1_TextChange();
    void brush_power_gear2_TextChange();
    void brush_power_gear3_TextChange();
    void on_open_serial_port_clicked();
    void ReadData();
    void on_send_data_clicked();

    void on_clear_recv_clicked();

    void on_find_serial_clicked();

private:
    Ui::MainWindow *ui;
    CanDevice *candevice;
    QThread* thread_rx ;
    QThread* thread_tx;
    QSerialPort *serial;
    HttpThread* http_thread;                   // HTTP请求线程
    WebsocketThread* websocket_thread;         // websocket线程

};

#endif // MAINWINDOW_H
